package com.sdut.material.controller;


import com.sdut.material.pojo.Supplier;
import com.sdut.material.service.ISupplierService;
import com.sdut.material.util.JSONResult;
import com.sdut.material.util.LayUITableResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author Yu
 * @since 2022-04-20
 */
@Controller
@RequestMapping("/supplier")
public class SupplierController {
    @Autowired
    private ISupplierService supplierService;
    @RequestMapping("selectById")
    @ResponseBody
    public JSONResult selectById(Integer id) {
        Supplier supplier = supplierService.selectById(id);
        return JSONResult.ok(supplier);
    }
    @RequestMapping("/getSupplierListPage")
    public String getSupplierListPage() {
        return "supplier/supplier_list";
    }
    @RequestMapping("/selectByPage")
    @ResponseBody
    public LayUITableResult selectByPage(Long page,Long limit) {
        return supplierService.selectByPage(page,limit);
    }
    @RequestMapping("/getSupplierInsertPage")
    public String getSupplierInsertPage() {
        return "supplier/supplier_insert";
    }
    @RequestMapping("/insert")
    @ResponseBody
    public JSONResult insert(Supplier supplier) {
        return supplierService.insert(supplier);
    }
    @RequestMapping("/getSupplierUpdatePage")
    public String getSupplierUpdatePage() {
        return "supplier/supplier_update";
    }
    @RequestMapping("/update")
    @ResponseBody
    public JSONResult updateSupplier(Supplier supplier) {
        return supplierService.updateSupplier(supplier);
    }
    @RequestMapping("/deleteById")
    @ResponseBody
    public JSONResult deleteById(Integer supplierId) {
        supplierService.deleteById(supplierId);
        return JSONResult.ok("删除成功");
    }
    @RequestMapping("/deleteAll")
    @ResponseBody
    public JSONResult deleteAll(String ids) {
        String[] idArray = ids.split(",");
        for (String supplierId : idArray) {
            deleteById(Integer.parseInt(supplierId));
        }
        return JSONResult.ok("删除成功");
    }
}

